<%@ page contentType="text/html;charset=utf-8"%>
<%@page import="com.leruan.aasimp.entity.Board"%>
<%@page import="com.leruan.aasimp.util.DateUtils"%>
<%@page import="com.leruan.aasimp.util.StringUtils"%>
<%@page import="com.leruan.aasimp.util.StringUtil"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page import="java.util.*"%>
<%@page import="com.leruan.aasimp.entity.Mainpost"%>
<%@page import="com.leruan.aasimp.entity.Forumuser"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
Forumuser user = (Forumuser)request.getSession().getAttribute("user");
Board board = (Board)request.getAttribute("board");
 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE></TITLE>
<LINK href="styles/green/ejforum.css" type=text/css rel=stylesheet>
<SCRIPT src="js/md5.js" type=text/javascript></SCRIPT>
<SCRIPT src="js/common.js" type=text/javascript></SCRIPT>
<SCRIPT type=text/javascript>
function checkfield(theform) {
    if(trim($('userID').value) == '') {
        $('userID').focus();    return false;
    } else if(trim($('pwd1').value) == '') {
        $('pwd1').focus(); return false;
    } else {
        $('pwd').value = hex_md5(trim($('pwd1').value)); 
        $('pwd1').value = '';
        theform.submit();return false;
    }
}
function toRegister(){
    window.location.href="toRegister";
}
function newTopic(boardId){
    if(<%=user==null%>){
        if(confirm("请先登录！")){
            document.location.href="loginOnly";
        }
    }else{
        document.location.href="newPost?boardId="+boardId;
    }
}
</SCRIPT>
</HEAD>
<BODY onkeydown="if(event.keyCode==27) return false;">
<s:actionerror cssStyle="color:red"/>
<DIV class=wrap>
<DIV id=header>
<table>
        <tr>
            <td >
                 <div style="height:73px; width: 193px; background-image: url('images/forumlogo.jpg')"></div>
            </td>
            <td align="right" width="1000%">
                <DIV id=foruminfo>
                <%if(null==user){
                %>
                <form action="login" onSubmit="checkfield(this); return false;" method="get">
                用户名：<input type=text id="username" name="username" size=13 maxlength=30 tabindex=1/>
                密码：<input type=password id="password1" name="password1" size=8 tabindex=2 onkeypress="if((event.keyCode?event.keyCode:event.charCode)==13) $('loginform').submit();"/>
                <INPUT type=hidden id="password" name="password">&nbsp;
                <button type="submit" name=loginsubmit tabIndex=3 style="width:46px">登录</button>
                <button type="button" name="register" tabIndex=3 style="width:46px" onclick="toRegister()">注册</button></form>
                <%
                } else{
                %>
                欢迎您!<a href="userDetails?username=<%=user.getUsername() %>&userId=<%=user.getUserId() %>"> <%=user.getUsername() %> <a href="logout.action">退出登录</a>
                <%
                }%>
                </DIV>
            </td>
        </tr>
    </table>
<DIV class="mainbox topiclist">
<H1>&raquo;&nbsp;<a href="index">首页</a>&raquo;&nbsp;<a href="boardPostList?boardId=<%=board.getBoardId()%>"><%=board.getBoardName() %></a>
<SPAN class=postbtn id="newtopictmp" onmouseover="$('newtopic').id = 'newtopictmp';this.id = 'newtopic';showMenu(this.id);">
<A href="javascript:newTopic('<%= board.getBoardId()%>');"><IMG src="styles/green/images/newtopic.gif" border=0></A></SPAN>
 </H1>
 <table cellSpacing=0 cellPadding=0>
	 <thead class="category">
		 <tr>
		      <td>&nbsp;</td>
		      <td>标题</td>
		      <td>作者</td>
		      <td>回复/查看</td>
		      <td>最后回复者</td>
		      <td>最后回复时间</td>
		 </tr>
	 </thead>
	 <tbody>
  <%
   List<Mainpost> mainPosts = (List<Mainpost>)request.getAttribute("mainPosts");
   Map<String,String> forumuserNameMap = (Map<String,String>)request.getAttribute("forumuserNameMap");
   Map<String,String> lastPostUserMap =(Map<String,String>)request.getAttribute("lastPostUserMap");
   Map<String,Date> lastPostTimeMap =(Map<String,Date>)request.getAttribute("lastPostTimeMap");
  int i=1;
  for(Mainpost mp:mainPosts){
  if(1==mp.getType()&&i<=5){
  %>
		 <tr>
		 <TD></TD>
    <TD>
        <IMG alt="置顶" src="images/top.jpg">&nbsp;
        <a href="viewPost?postId=<%=mp.getPostId() %>"><%=mp.getPostTitle()%></a>
    </TD>
    <TD class=author>
        <%=forumuserNameMap.get(mp.getUserId()) %>
    </TD>
    <TD ><A href="viewPost?postId=<%=mp.getPostId() %>" >回复/查看</A> 
    </TD>
    <TD>
    <%=StringUtils.ignoreNull(lastPostUserMap.get(mp.getPostId())) %>
    </TD>
    <TD>
    <%=StringUtils.ignoreNull(DateUtils.date2StringBySecond(lastPostTimeMap.get(mp.getPostId())))%>
    </TD>
		 </tr>
  <%i++;}}
   %>
	 </tbody>
 </table>
<TABLE cellSpacing=0 cellPadding=0>
  <THEAD class=category>
  <TR>
  	<TD>&nbsp;</TD>
    <TD>标题</TD>
	<TD>作者</TD>
    <TD>回复/查看</TD>
    <TD>最后回复者</TD>
    <TD>最后回复时间</TD>
  </TR>
  </THEAD>
  <TBODY>
    <%
    mainPosts = (List<Mainpost>)request.getAttribute("mainPosts");
    forumuserNameMap = (Map<String,String>)request.getAttribute("forumuserNameMap");
    lastPostUserMap =(Map<String,String>)request.getAttribute("lastPostUserMap");
    lastPostTimeMap =(Map<String,Date>)request.getAttribute("lastPostTimeMap");
  for(Mainpost mp1:mainPosts){
  if(1!=mp1.getType()&&2!=mp1.getType()){
  %>
  <TR>
  <TD></TD>
    <TD>
		<IMG alt="精华" src="images/digest.gif">&nbsp;
		<a href="viewPost?postId=<%=mp1.getPostId() %>"><%=mp1.getPostTitle()%></a>
	</TD>
	<TD class=author>
		<%=forumuserNameMap.get(mp1.getUserId()) %>
	</TD>
    <TD ><A href="viewPost?postId=<%=mp1.getPostId() %>" >回复/查看</A> 
    </TD>
    <TD>
    <%=StringUtils.ignoreNull(lastPostUserMap.get(mp1.getPostId())) %>
    </TD>
    <TD>
    <%=StringUtils.ignoreNull(DateUtils.date2StringBySecond(lastPostTimeMap.get(mp1.getPostId())))%>
    </TD>
    </TR>
  
  <%
  }}
   %>
    </TBODY>
    <%if(mainPosts==null){
		%>
			<tbody><tr><td class=folder>&nbsp;</td><th colspan="4">目前尚无此类型主题</th></tr></tbody>
		<%
    } %>
</TABLE>
</DIV>
<div class="pageNo" id="pageNo">
                <a href="boardPostListQuery?no=1&boardId=<%=board.getBoardId() %>">首页</a>
                <c:if test="${sessionScope.pageNoSale != 1}">
                    <a href="boardPostListQuery?no=${sessionScope.pageNoSale-1}&boardId=<%=board.getBoardId() %>">上一页</a>
                </c:if>
                <c:forEach var="i" begin="${sessionScope.pageNoCenterSale -2 }"
                    end="${sessionScope.pageNoCenterSale + 2}">
                    <c:if test="${i <= sessionScope.totalNoSale }">
                        <c:choose>
                            <c:when test="${i == sessionScope.pageNoSale}">
                                <a href="javascript:void(0)">${i}</a>
                            </c:when>
                            <c:otherwise>
                                <a href="boardPostListQuery?no=${i}&boardId=<%=board.getBoardId() %>">${i}</a>
                            </c:otherwise>
                        </c:choose>
                    </c:if>
                </c:forEach>
                <c:if test="${sessionScope.pageNoSale +4 < sessionScope.totalNoSale}">
                    <a href="boardPostListQuery?no=${sessionScope.pageNoSale+1}&boardId=<%=board.getBoardId() %>">下一页</a>
                </c:if>
                <a href="boardPostListQuery?no=${sessionScope.totalNoSale}&boardId=<%=board.getBoardId() %>">末页</a>
                &nbsp;&nbsp;&nbsp;&nbsp;共有<label style="color: red;">${sessionScope.totalSale}</label>条帖子
            </div>
<DIV class=pages_btns>
</DIV>
</DIV>
</BODY></HTML>
